package com.itheima.dao;

import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface RoleDao {
    @Select("select r.* from t_role r,t_user_role ur where ur.role_id=r.id and ur.user_id =#{id}")
    Set<Role> findRolesByUid(Integer id);
    @Select("SELECT t2.path, t2.name title,t2.icon,t2.id FROM t_role_menu t1,t_menu t2 WHERE t1.menu_id=t2.id AND t1.role_id=(SELECT t1.id FROM  t_role t1,t_user_role t2 WHERE t1.id=t2.role_id AND t2.user_id=#{id}) AND ISNULL(t2.parentMenuId)\n")
    List<Map> findParentMenu(int id);
     @Select("select path,name title,linkUrl, id from t_menu where parentMenuId=#{meuId}")
    List<Map> findChildByParentId(Integer meuId);
    @Select("select tr.name from t_role_permission trp,t_role tr where trp.role_id=tr.id and trp.permission_id=#{id}")
    Set<String> findRolesNameByPid(Integer id);
@Select("SELECT t.`name` FROM t_user_role ur,t_role t WHERE ur.role_id=t.id AND ur.user_id=(SELECT id FROM t_user WHERE username=#{username}) ")
    String findRolesNameByUname(String username);
}
